#include "mainwindow.h"
#include <QMenuBar>
#include <QMenu>
#include <QAction>
#include <qDebug>
#include <QToolBar>
#include <QPushButton>
#include <QStatusBar>
#include <QLabel>
#include <QTextEdit>
#include <QDockWidget>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    resize(600, 400);

    // 菜单栏
    QMenuBar *mBar = menuBar();

    // 添加菜单
    QMenu *pFile = mBar->addMenu("文件");


    // 添加菜单项, 添加动作
    QAction *pNew  = pFile->addAction("新建");
    connect(pNew, &QAction::triggered,
            [=]() {
                qDebug() << "新建被按下";
            }
    );

    QAction *pOpen = pFile->addAction("打开");

    // 添加分割线
    pFile->addSeparator();

    connect(pOpen, &QAction::triggered,
            [=]() {
                qDebug() << "打开被按下";
            }
     );


    // 工具栏
    QToolBar *toolBar = addToolBar("toolbar");
    toolBar->addAction(pNew);

    QPushButton *btn = new QPushButton(this);
    btn->setText("^_^");
    // 工具栏添加小控件
    toolBar->addWidget(btn);

    connect(btn, &QPushButton::clicked,
            [=]() {
                btn->setText("@_@");
            }
    );

    // 状态栏
    QStatusBar *staBar = statusBar();
    QLabel *lable = new QLabel(this);
    lable->setText("Normal text file");
    // addWidget 从左往右添加
    staBar->addWidget(lable);
    staBar->addWidget(new QLabel("2", this));

    // addPermanentWidget 从右往左添加
    staBar->addPermanentWidget(new QLabel("右边", this));

    // 核心控件
    QTextEdit *edit = new QTextEdit(this);
    setCentralWidget(edit);

    // 浮动窗口
    QDockWidget *dock = new QDockWidget(this);
    addDockWidget(Qt::RightDockWidgetArea, dock);

    // 给浮动窗口添加文本编辑区
    QTextEdit *edit2 = new QTextEdit(this);
    dock->setWidget(edit2);
}

MainWindow::~MainWindow()
{

}
